unit WinDos;

interface

uses Windows, SysUtils;

Function WinString(DosString: String): String;
Function DosString(WinString: String): String;
procedure DosToWin(DosString: PChar);
procedure WinToDos(WinString: PChar);

implementation

Function WinString(DosString: String): String;
var s: PChar;
begin
  s := StrNew(PChar(DosString));
  OemToChar(s, s);
  result := s;
end;

Function DosString(WinString: String): String;
var s: PChar;
begin
  s := StrNew(PChar(WinString));
  CharToOem(s, s);
  result := s;
end;

{Function WinString(DosString: String): String;
var
  i, Len: Integer;
  Code: Longint;
  DosChar, WinChar: Char;
  RetVal: String;
begin
  RetVal:= '';
  For i:= 1 To Length(DosString) do
  begin
    DosChar:= DosString[i];
    Code:= Ord(DosChar);
    Case Code of
      128..175: WinChar:= Chr(Code + 64);
      224..239: WinChar:= Chr(Code + 16);
      240: WinChar:= Chr(168);
      241: WinChar:= Chr(184);
      252: WinChar:= Chr(185);
      253: WinChar:= Chr(164)
    Else
      WinChar:= DosChar;
    End;
    Len:= Length(RetVal);
    RetVal := RetVal + ' ';
    RetVal[Len + 1]:= WinChar;
  end;
  WinString:= RetVal;
End;}

{Function DosString(WinString: String): String;
var
  i, Len: Integer;
  Code: Longint;
  DosChar, WinChar: Char;
  RetVal: string;
begin
  RetVal:= '';
  For i:= 1 To Length(WinString) do
  begin
    WinChar:= WinString[i];
    Code:= Ord(WinChar);
    Case Code of
      192..239: DosChar:= Chr(Code - 64);
      240..255: DosChar:= Chr(Code - 16);
      168: DosChar:= Chr(240);
      184: DosChar:= Chr(241);
      185: DosChar:= Chr(252);
      164: DosChar:= Chr(253)
    Else
      DosChar:= WinChar;
    End;
    Len:= Length(RetVal);
    SetLength(RetVal, Len+1);
    RetVal[Len + 1]:= DosChar;
  End;
  DosString:= RetVal;
End;}

procedure DosToWin(DosString: PChar);
var
  p: PChar;
  Code: Longint;
  WinChar: Char;
begin
  p := DosString;
  While p^ <> #0 do
  begin
    Code:= Ord(p^);
    Case Code of
      128..175: WinChar:= Chr(Code + 64);
      224..239: WinChar:= Chr(Code + 16);
      240: WinChar:= Chr(168);
      241: WinChar:= Chr(184);
      252: WinChar:= Chr(185)
    Else
      WinChar:= p^;
    End;
    p^ := WinChar;
    p := p + 1;
  end;
end;

procedure WinToDos(WinString: PChar);
var
  p: PChar;
  Code: Longint;
  DosChar: Char;
begin
  p := WinString;
  While p^ <> #0 do
  begin
    Code:= Ord(p^);
    Case Code of
      192..239: DosChar:= Chr(Code - 64);
      240..255: DosChar:= Chr(Code - 16);
      168: DosChar:= Chr(240);
      184: DosChar:= Chr(241);
      185: DosChar:= Chr(252)
    Else
      DosChar:= p^;
    End;
    p^ := DosChar;
    p := p + 1;
  end;
end;

end.
